package com.lyf.juc.learn.sggadvance.locks;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @author LYF
 * @date 2022/7/2
 */
public class LockTests {
    /*
    悲观锁
     */
    public void test1(){
        synchronized (this){

        }

        Lock lock = new ReentrantLock();
        lock.lock();
        try {

        }catch (Exception e){

        }finally {
            lock.unlock();
        }

        AtomicInteger atomicInteger = new AtomicInteger();
        atomicInteger.getAndIncrement();//CAS
        /*
            public final int getAndAddInt(Object o, long offset, int delta) {
        int v;
        do {
            v = getIntVolatile(o, offset);
        } while (!weakCompareAndSetInt(o, offset, v, v + delta));
        return v;
           }

             public final native boolean compareAndSetInt(Object o, long offset,
                                                 int expected,
                                                 int x);
         */

    }



}
